class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        // 层序遍历需要借助一个队列
        queue<TreeNode*> q;
        vector<vector<int>> des;
        // 借助一个队列来完成二叉树的层序遍历
        if(root == nullptr)
        {
            return des;
        }
        q.push(root);
        while (q.size()) 
        {
            int size = q.size();//获取这一层具有的节点个数
            vector<int> mem;
            for (int i = 0; i < size; i++) 
            {
                TreeNode* frt = q.front();
                q.pop();
                if (frt->left) {
                    q.push(frt->left);
                }
                if (frt->right) {
                    q.push(frt->right);
                }
                mem.push_back(frt->val);
            }
            des.push_back(mem);
            mem.clear();
        }
        return des;
    }
};